(function ($) {
    var deptId = "";
    $.userInfoMgr = {
        state: [{id: 0, text: "生效"}, {id: 1, text: "不生效"}, {id: 2, text: "锁定"}],
        loginSource: [{id: 0, text: "不区分"}, {id: 1, text: "限定安全管控"}, {id: 2, text: "限定门户登录"}],
        initButton: function () {
            $("#addData").on('click', $.userInfoOper.addUserInfo);
            $("#updateData").on('click', $.userInfoOper.updateUserInfo);
            $("#delData").on('click', $.userInfoOper.delUserInfo);
            $("#userRole").on('click', $.userInfoOper.userRoleOper);
            $("#passCfg").on('click', $.userInfoOper.passCfg);
        },
        initTable: function (treeNode) {
            deptId = treeNode.organizationId;
            $('#mainContent').show();
            $('#userTable').bootstrapTable('destroy');
            $('#userTable')
                .bootstrapTable(
                    {
                        height: '100%',
                        method: 'get',
                        url: basePath + 'loginUser/getUserList.do?deptId=' + deptId,
                        dataType: "json",
                        striped: true,// 使表格有条纹
                        pagination: true,// 在表格底部显示分页
                        pageNumber: 1,
                        pageSize: 20,
                        cache: false,// 是否使用缓存
                        pageList: [20, 50, 100],
                        paginationLoop: false,
                        idField: 'userId',// 标识哪个字段为id主键
                        sidePagination: "client",// 表格分页的位置
                        queryParamsType: "", // 参数格式,发送标准的RESTFul类型的参数请求
                        clickToSelect: true,//点击行即可选中单选/复选框
                        sortable: true,
                        showRefresh: true,
                        toolbar: '#toolbar',
                        search: true,//是否显示右上角的搜索框
                        queryParams: function (params) {

                        }, //参数
                        columns: [{
                            checkbox: true
                        }, {
                            field: 'USER_ID',
                            title: '用户ID',
                            visible: false
                        }, {
                            field: 'CN_NAME',
                            title: '用户名称'
                        }, {
                            field: 'LOGIN_NAME',
                            title: '登录名称'
                        }, {
                            field: 'ORGANIZATION_ID',
                            title: '所属部门',
                            visible: false
                        }, {
                            field: 'ORGANIZATION_NAME',
                            title: '所属部门'
                        }, {
                            field: 'STATE',
                            title: '状态',
                            formatter: $.userMgrFormatter.stateFormatter
                        }]
                    });
            $('#userTable').bootstrapTable(
                'resetView',
                {
                    height: $(window).height() - 70
                });
        }
    };
    $.userMgrFormatter = {
        stateFormatter: function (value, row, index) {
            if (value == '1') {
                return '<span class="badge">不生效</span>';
            } else if (value == '0') {
                return '<span class="badge badge-success">生效</span>';
            } else if (value == '2') {
                return '<span class="badge badge-warning">锁定</span>';
            } else {
                return '<span class="badge">不生效</span>';
            }
        }
    };
    $.initTree = {
        initTreePanel: function () {
            var rootNode = [];
            var setting = {
                async: {
                    enable: true,
                    url: basePath + "loginUser/getGroupInfoWithUser.do",
                    autoParam: ["organizationId", "parentId", "level"],
                    type: 'get'
                },
                view: {
                    dblClickExpand: false,
                    showLine: true,
                    selectedMulti: false
                },
                data: {
                    key: {
                        name: 'name'
                    },
                    simpleData: {
                        enable: true,
                        idKey: "organizationId",
                        pIdKey: "parentId",
                        rootPId: "0"
                    }
                },
                callback: {
                    onClick: function (event, treeId, treeNode) {
                        $.initTree.treeOnClick(event, treeId, treeNode);
                    }
                }
            };
            var t = $("#tree");
            t = $.fn.zTree.init(t, setting, rootNode);
            $("#tree").css('height', $(window).height() - 70);
        },
        /*
         * 点击树打开页面
         */
        treeOnClick: function (event, treeId, treeNode) {
            $.userInfoMgr.initTable(treeNode);
        },
        /*
         * 浏览器大小发生变化
         */
        treeResize: function () {
            $(window).resize(function () {
                $("#tree").css('height', $(window).height() - 40);
            });
        }
    };
    $.userInfoOper = {
        validOptions: {
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            message: '值未验证通过',
            group: '.v-group',
            fields: {
                userNameForm: {validators: {notEmpty: {message: '请填写用户名称'}}},
                loginNameForm: {
                    validators: {
                        notEmpty: {message: '请填写登录名称'},
                        threshold: 2,//只有2个字符以上才发送ajax请求
                        remote: {
                            url: basePath + "loginUser/checkLoginNameUnique.do",
                            data: function (validator) {
                                return {
                                    loginName: $("#loginName-form").val()
                                };
                            },
                            type: 'GET',
                            message: '该登陆名已经被使用',
                            delay: 2000
                        }
                    }
                },
                stateForm: {validators: {notEmpty: {message: '请选择状态'}}},
                organizationForm:{validators: {notEmpty: {message: '请选择部门'}}},
                roleForm:{validators: {notEmpty: {message: '请选择角色'}}}
                // userPermitForm: {validators: {notEmpty: {message: '请选择用户职能'}}},
                // loginSourceForm: {validators: {notEmpty: {message: '请选择登陆限定'}}},
                // provinceIdForm: {validators: {notEmpty: {message: '请选择所属省份'}}},
                // emailForm: {validators: {emailAddress: {message: '邮箱地址格式有误'}}},
                // mobileForm: {
                //     validators: {
                //         stringLength: {
                //             min: 11,
                //             max: 11,
                //             message: '请输入11位手机号码'
                //         },
                //         regexp: {
                //             regexp: /^1[3|4|5|7|8]{1}[0-9]{9}$/,
                //             message: '请输入正确的手机号码'
                //         }
                //     }
                // }
            }
        },
        getForm: function (needInit) {
            var $tableDataDiv = $('<form id="tableForm" role="form" class="form-horizontal"></form>');

            var $tableInfo = $('<div class="form-group"></div>');
            $tableInfo.append('<div class="v-group"><label for="loginName-form" class="col-md-2 col-sm-2 col-xs-2 control-label" ' +
                '>登录名称</label><div class="col-md-4 col-sm-4 col-xs-10 ">' +
                '<input type="text" id="loginName-form" class="form-control" name="loginNameForm" placeholder="登录名称"/></div></div>');
            $tableInfo.append('<div class="v-group"><label for="userName-form" class="col-md-2 col-sm-2 col-xs-2 control-label" ' +
                '>用户名称</label><div class="col-md-4 col-sm-4 col-xs-10 ">' +
                '<input type="text" id="userName-form" class="form-control" name="userNameForm" placeholder="用户名称"/></div></div>');
            $tableDataDiv.append($tableInfo);

            $tableInfo = $('<div class="form-group"></div>');
            $tableInfo.append('<div class="v-group"><label for="development-form" class="col-md-2 col-sm-2 col-xs-2 control-label" ' +
                '>部门</label><div class="col-md-4 col-sm-4 col-xs-10 ">' +
                '<select class="form-control select2" id="development-form" name="developmentForm" placeholder="部门"></select></div></div>');
            $tableInfo.append('<div class="v-group"><label for="state-form" class="col-md-2 col-sm-2 col-xs-2 control-label" ' +
                '>状态</label><div class="col-md-4 col-sm-4 col-xs-10 ">' +
                '<select class="form-control select2" id="state-form" name="stateForm" placeholder="状态"></select></div></div>');
            $tableDataDiv.append($tableInfo);

            if (!needInit) {
                $tableInfo.append('<div class="col-md-12 col-sm-12 col-xs-10 text-center" style="color:red;"><br>提示：新增用户默认密码为：88888888。</div>');
            }
            $tableDataDiv.append($tableInfo);
            // $tableInfo = $('<div class="form-group"></div>');
            // $tableInfo.append('<div class="v-group"><label for="mobile-form" class="col-md-2 col-sm-2 col-xs-2 control-label" ' +
            //     '>手机号</label><div class="col-md-4 col-sm-4 col-xs-10 ">' +
            //     '<input type="text" id="mobile-form" class="form-control" name="mobileForm" placeholder="手机号（可选）"/></div></div>');
            // $tableInfo.append('<div class="v-group"><label for="userPermit-form" class="col-md-2 col-sm-2 col-xs-2 control-label" ' +
            //     '>用户职能</label><div class="col-md-4 col-sm-4 col-xs-10 ">' +
            //     '<select class="form-control select2" id="userPermit-form" name="userPermitForm" placeholder="用户职能"></select></div></div>');
            // $tableDataDiv.append($tableInfo);
            // $tableInfo = $('<div class="form-group"></div>');
            // $tableInfo.append('<div class="v-group"><label for="loginSource-form" class="col-md-2 col-sm-2 col-xs-2 control-label" ' +
            //     '>登陆限定</label><div class="col-md-4 col-sm-4 col-xs-10 ">' +
            //     '<select class="form-control select2" id="loginSource-form" name="loginSourceForm" placeholder="登陆限定"></select></div></div>');
            // $tableInfo.append('<div class="v-group"><label for="provinceId-form" class="col-md-2 col-sm-2 col-xs-2 control-label" ' +
            //     '>所属省份</label><div class="col-md-4 col-sm-4 col-xs-10 ">' +
            //     '<select class="form-control select2" id="provinceId-form" name="provinceIdForm" placeholder="所属省份"></select></div></div>');
            // $tableDataDiv.append($tableInfo);
            // $tableInfo = $('<div class="form-group"></div>');
            // $tableInfo.append('<div class="v-group"><label for="cityId-form" class="col-md-2 col-sm-2 col-xs-2 control-label" ' +
            //     '>所属地市</label><div class="col-md-4 col-sm-4 col-xs-10 ">' +
            //     '<select class="form-control select2" id="cityId-form" name="cityIdForm" placeholder="所属地市"></select></div></div>');
            // $tableInfo.append('<div class="v-group"><label for="districtId-form" class="col-md-2 col-sm-2 col-xs-2 control-label" ' +
            //     '>所属地区</label><div class="col-md-4 col-sm-4 col-xs-10 ">' +
            //     '<select class="form-control select2" id="districtId-form" name="districtIdForm" placeholder="所属地区"></select></div></div>');
            // $tableDataDiv.append($tableInfo);
            // $tableInfo = $('<div class="form-group"></div>');
            // $tableInfo.append('<div class="v-group"><label for="description-form" class="col-md-2 col-sm-2 col-xs-2 control-label" ' +
            //     '>用户描述</label><div class="col-md-10 col-sm-10 col-xs-10 ">' +
            //     '<input type="text" id="description-form" class="form-control" name="cnNameForm" placeholder="用户描述（可选）"/></div></div>');

            //
            // $tableInfo.append('<div class="v-group"><label for="email-form" class="col-md-2 col-sm-2 col-xs-2 control-label" ' +
            //     '>邮箱</label><div class="col-md-4 col-sm-4 col-xs-10 ">' +
            //     '<input type="text" id="email-form" class="form-control" name="emailForm" placeholder="邮箱（可选）"/></div></div>');

            return $tableDataDiv;
        },
        addUserInfo: function () {
            BootstrapDialog.show({
                size: BootstrapDialog.SIZE_WIDE,
                draggable: true,
                title: '新增用户信息',
                message: $.userInfoOper.getForm(false),
                buttons: [{
                    label: '提交',
                    action: function (dialogRef) {
                        var validate = $("#tableForm").data('bootstrapValidator').validate();
                        if (!validate.isValid()) {
                            return;
                        }
                        var zTreeObj = $.fn.zTree.getZTreeObj("tree");
                        var zTree = zTreeObj.getSelectedNodes(true);
                        var organizationId = zTree[0].organizationId;
                        $.ajax({
                            url: basePath + 'loginUser/saveUserInfoData.do',
                            type: 'POST',
                            data: {
                                name: $('#tableForm #userName-form').val(),
                                loginName: $('#tableForm #loginName-form').val(),
                                // email: $('#tableForm #email-form').val(),
                                // description: $('#tableForm #description-form').val(),
                                state: $('#tableForm #state-form').val(),
                                // loginSource: $('#tableForm #loginSource-form').val(),
                                // mobile: $('#tableForm #mobile-form').val(),
                                // provinceId: $('#tableForm #provinceId-form').val(),
                                // cityId: $('#tableForm #cityId-form').val(),
                                // districtId: $('#tableForm #districtId-form').val(),
                                // userPermit: $('#tableForm #userPermit-form').val(),
                                organization: $('#tableForm #development-form').val()
                            },
                            async: true,
                            dataType: 'json',
                            beforeSend: function () {
                                MaskLoading.fullScreenShow("正在提交,请稍后...");
                            },
                            success: function (data) {
                                if (data.success) {
                                    noty({
                                        text: "新增数据成功",
                                        layout: "center",
                                        type: "success",
                                        timeout: 1000,
                                        theme: 'bootstrapTheme'
                                    });
                                    MaskLoading.fullScreenHide();
                                    dialogRef.close();
                                    $.userInfoOper.refreshData();
                                } else {
                                    noty({
                                        text: data.message.errorMessage,
                                        layout: "center",
                                        type: "error",
                                        timeout: 1000,
                                        theme: 'bootstrapTheme'
                                    });
                                    MaskLoading.fullScreenHide();
                                }
                            },
                            error: function (data) {
                                noty({
                                    text: "服务器异常",
                                    layout: "center",
                                    type: "error",
                                    timeout: 1000,
                                    theme: 'bootstrapTheme'
                                });
                                MaskLoading.fullScreenHide();
                            },
                            complete: function () {
                                MaskLoading.fullScreenHide();
                            }
                        });
                    }
                }, {
                    label: '关闭',
                    action: function (dialogRef) {
                        dialogRef.close();
                    }
                }],
                onshown: function (dialogRef) {

                    $.userSelect.stateSelect();
                    var zTreeObj = $.fn.zTree.getZTreeObj("tree");
                    var zTree = zTreeObj.getSelectedNodes(true);
                    let organizationValue = [{
                        id: zTree[0].organizationId,
                        text: zTree[0].name
                    }];

                    $.userSelect.developmentSelect(organizationValue);
                    let roleValue = [{
                       id: '5',
                       text: '一般教师'
                    }];
                    $.userSelect.roleSelect(roleValue);
                    $("#tableForm").bootstrapValidator($.userInfoOper.validOptions);


                }
            });
        },
        updateUserInfo: function () {
            var selections = $('#userTable').bootstrapTable('getSelections');
            if (selections.length == 0) {
                noty({
                    text: "请勾选需要操作的记录",
                    layout: "center",
                    type: "error",
                    timeout: 1000,
                    theme: 'bootstrapTheme'
                });
                return false;
            }
            if (selections.length > 1) {
                noty({
                    text: "只能勾选一条需要操作的记录",
                    layout: "center",
                    type: "error",
                    timeout: 1000,
                    theme: 'bootstrapTheme'
                });
                return false;
            }
            BootstrapDialog.show({
                size: BootstrapDialog.SIZE_WIDE,
                draggable: true,
                title: '修改用户信息',
                message: $.userInfoOper.getForm(true),
                buttons: [{
                    label: '提交',
                    action: function (dialogRef) {
                        var validate = $("#tableForm").data('bootstrapValidator').validate();
                        if (!validate.isValid()) {
                            return;
                        }
                        var zTreeObj = $.fn.zTree.getZTreeObj("tree");
                        var zTree = zTreeObj.getSelectedNodes(true);
                        var organizationId = zTree[0].organizationId;
                        $.ajax({
                            url: basePath + 'loginUser/saveUserInfoData.do',
                            type: 'POST',
                            data: {
                                // name: $('#tableForm #userName-form').val(),
                                // loginName: $('#tableForm #loginName-form').val(),
                                // email: $('#tableForm #email-form').val(),
                                // description: $('#tableForm #description-form').val(),
                                // state: $('#tableForm #state-form').val(),
                                // loginSource: $('#tableForm #loginSource-form').val(),
                                // mobile: $('#tableForm #mobile-form').val(),
                                // provinceId: $('#tableForm #provinceId-form').val(),
                                // cityId: $('#tableForm #cityId-form').val(),
                                // districtId: $('#tableForm #districtId-form').val(),
                                // userPermit: $('#tableForm #userPermit-form').val(),
                                // userId: selections[0].userId,
                                // organization: organizationId
                                userId: selections[0].USER_ID,
                                name: $('#tableForm #userName-form').val(),
                                loginName: $('#tableForm #loginName-form').val(),
                                // email: $('#tableForm #email-form').val(),
                                // description: $('#tableForm #description-form').val(),
                                state: $('#tableForm #state-form').val(),
                                // loginSource: $('#tableForm #loginSource-form').val(),
                                // mobile: $('#tableForm #mobile-form').val(),
                                // provinceId: $('#tableForm #provinceId-form').val(),
                                // cityId: $('#tableForm #cityId-form').val(),
                                // districtId: $('#tableForm #districtId-form').val(),
                                // userPermit: $('#tableForm #userPermit-form').val(),
                                organization: $('#tableForm #development-form').val()
                            },
                            async: true,
                            dataType: 'json',
                            beforeSend: function () {
                                MaskLoading.fullScreenShow("正在提交,请稍后...");
                            },
                            success: function (data) {
                                if (data.success) {
                                    noty({
                                        text: "修改数据成功",
                                        layout: "center",
                                        type: "success",
                                        timeout: 1000,
                                        theme: 'bootstrapTheme'
                                    });
                                    MaskLoading.fullScreenHide();
                                    dialogRef.close();
                                    $.userInfoOper.refreshData();
                                } else {
                                    noty({
                                        text: data.message.errorMessage,
                                        layout: "center",
                                        type: "error",
                                        timeout: 1000,
                                        theme: 'bootstrapTheme'
                                    });
                                    MaskLoading.fullScreenHide();
                                }
                            },
                            error: function (data) {
                                noty({
                                    text: "服务器异常",
                                    layout: "center",
                                    type: "error",
                                    timeout: 1000,
                                    theme: 'bootstrapTheme'
                                });
                                MaskLoading.fullScreenHide();
                            },
                            complete: function () {
                                MaskLoading.fullScreenHide();
                            }
                        });
                    }
                }, {
                    label: '关闭',
                    action: function (dialogRef) {
                        dialogRef.close();
                    }
                }],
                onshown: function (dialogRef) {
                    var zTreeObj = $.fn.zTree.getZTreeObj("tree");
                    var zTree = zTreeObj.getSelectedNodes(true);
                    var organizationId = zTree[0].organizationId;

                    let stateName = '';
                    console.log(JSON.stringify(selections));
                    console.log(selections[0].STATE);
                    for(var p in $.userInfoMgr.state){
                        if(p.id == selections[0].STATE){
                            stateName = p.text;
                            break;
                        }
                    }

                    let stateValue = [{
                        id: selections[0].STATE,
                        text: stateName
                    }];

                    let organizationValue = [{
                        id: selections[0].ORGANIZATION_ID,
                        text: selections[0].ORGANIZATION_NAME
                    }];
                    console.log(JSON.stringify(stateValue));
                    $.userSelect.stateSelect(stateValue);
                    $.userSelect.developmentSelect(organizationValue);
                    $("#userName-form").val(selections[0].CN_NAME);
                    $("#loginName-form").val(selections[0].LOGIN_NAME);
                    $("#loginName-form").attr("readonly", "readonly");
                    // $.userSelect.createChange();
                    $("#tableForm").bootstrapValidator($.userInfoOper.validOptions);
                    $('#tableForm').data('bootstrapValidator').enableFieldValidators('loginNameForm', false);
                }
            });
        },
        delUserInfo: function () {
            var selections = $('#userTable').bootstrapTable('getSelections');
            if (selections.length == 0) {
                noty({
                    text: "请勾选需要操作的记录",
                    layout: "center",
                    type: "error",
                    timeout: 1000,
                    theme: 'bootstrapTheme'
                });
                return false;
            }
            if (selections.length > 1) {
                noty({
                    text: "只能勾选一条需要操作的记录",
                    layout: "center",
                    type: "error",
                    timeout: 1000,
                    theme: 'bootstrapTheme'
                });
                return false;
            }
            BootstrapDialog.confirm({
                draggable: true,
                title: "删除用户",
                btnOKLabel: '是',
                btnCancelLabel: '否',
                message: '确定要进行删除操作吗?',
                callback: function (result) {
                    if (result) {
                        $.ajax({
                            url: basePath + 'loginUser/delUserInfoData.do',
                            type: 'POST',
                            data: {userId: selections[0].USER_ID},
                            async: true,
                            dataType: 'json',
                            beforeSend: function () {
                                MaskLoading.fullScreenShow("正在提交,请稍后...");
                            },
                            success: function (data) {
                                if (data.success) {
                                    noty({
                                        text: "删除数据成功",
                                        layout: "center",
                                        type: "success",
                                        timeout: 1000,
                                        theme: 'bootstrapTheme'
                                    });
                                    MaskLoading.fullScreenHide();
                                    $.userInfoOper.refreshData();
                                } else {
                                    noty({
                                        text: data.message.errorMessage,
                                        layout: "center",
                                        type: "error",
                                        timeout: 1000,
                                        theme: 'bootstrapTheme'
                                    });
                                    MaskLoading.fullScreenHide();
                                }
                            },
                            error: function (data) {
                                noty({
                                    text: "服务器异常",
                                    layout: "center",
                                    type: "error",
                                    timeout: 1000,
                                    theme: 'bootstrapTheme'
                                });
                            },
                            complete: function () {
                                MaskLoading.fullScreenHide();
                            }
                        });
                    }
                }
            });
        },
        getAuthForm: function () {
            var $tabDiv = $('<div></div>');
            var $tabContentDiv = $('<div id="myTabContent" class="tab-content"></div>');
            $tabContentDiv.append('<div class="tab-pane fade in active" id="role"><select multiple="multiple" size="10" name="roleSelect" id="roleSelect"></select></div>');
            $tabDiv.append($tabContentDiv);
            return $tabDiv;
        },
        userRoleOper: function () {
            var selections = $('#userTable').bootstrapTable('getSelections');
            if (selections.length == 0) {
                noty({
                    text: "请勾选需要操作的记录",
                    layout: "center",
                    type: "error",
                    timeout: 1000,
                    theme: 'bootstrapTheme'
                });
                return false;
            }
            if (selections.length > 1) {
                noty({
                    text: "只能勾选一条需要操作的记录",
                    layout: "center",
                    type: "error",
                    timeout: 1000,
                    theme: 'bootstrapTheme'
                });
                return false;
            }
            var userId = selections[0].USER_ID;
            BootstrapDialog.show({
                size: BootstrapDialog.SIZE_WIDE,
                draggable: true,
                closeByBackdrop: false,
                closeByKeyboard: false,
                title: "角色配置",
                message: $.userInfoOper.getAuthForm(),
                buttons: [{
                    label: '提交',
                    action: function (dialogRef) {
                        let roleSelectData = $('#roleSelect').val();
                        if (roleSelectData) {
                            roleSelectData = roleSelectData.join(",");
                            $.ajax({
                                url: basePath + 'loginUser/saveUserRole.do',
                                type: 'POST',
                                data: {
                                    userId: userId,
                                    roleSelectData: roleSelectData
                                },
                                async: true,
                                dataType: 'json',
                                beforeSend: function () {
                                    MaskLoading.fullScreenShow("正在提交,请稍后...");
                                },
                                success: function (data) {
                                    MaskLoading.fullScreenHide();
                                    if (data.success) {
                                        noty({
                                            text: "配置成功",
                                            layout: "center",
                                            type: "success",
                                            timeout: 1000,
                                            theme: 'bootstrapTheme'
                                        });
                                        $.userInfoOper.refreshData();
                                        dialogRef.close();
                                    } else {
                                        noty({
                                            text: data.message.errorMessage,
                                            layout: "center",
                                            type: "error",
                                            timeout: 1000,
                                            theme: 'bootstrapTheme'
                                        });
                                    }
                                },
                                error: function (data) {
                                    MaskLoading.fullScreenHide();
                                    noty({
                                        text: "服务调用失败",
                                        layout: "center",
                                        type: "error",
                                        timeout: 1000,
                                        theme: 'bootstrapTheme'
                                    });
                                }

                            });
                            dialogRef.close();
                        } else {
                            noty({
                                text: "请选择分配的角色信息",
                                layout: "center",
                                type: "error",
                                timeout: 1000,
                                theme: 'bootstrapTheme'
                            });
                        }
                    }
                }, {
                    label: '关闭',
                    action: function (dialogRef) {
                        dialogRef.close();
                    }
                }],
                onshown: function (dialogRef) {
                    $.ajax({
                        url: basePath + 'loginUser/getUserRole.do',
                        type: 'GET',
                        data: {
                            userId: userId
                        },
                        async: true,
                        dataType: 'json',
                        beforeSend: function () {
                            MaskLoading.fullScreenShow("正在获取用户信息,请稍后...");
                        },
                        success: function (data) {
                            MaskLoading.fullScreenHide();
                            if (data.success) {
                                let nonSelected = data.message.nonSelected;
                                let selected = data.message.selected;
                                $('#roleSelect').doublebox({
                                    nonSelectedListLabel: '选择角色',
                                    selectedListLabel: '授权用户与角色关系',
                                    preserveSelectionOnMove: 'moved',
                                    filterPlaceHolder: '筛选',
                                    selectorMinimalHeight: $(window).height() / 2,
                                    moveOnSelect: false,
                                    nonSelectedList: nonSelected,
                                    selectedList: selected,
                                    optionValue: "roleId",
                                    optionText: "name",
                                    doubleMove: true
                                });
                            } else {
                                noty({
                                    text: data.message.errorMessage,
                                    layout: "center",
                                    type: "error",
                                    timeout: 2000,
                                    theme: 'bootstrapTheme'
                                });
                            }
                        },
                        error: function (data) {
                            MaskLoading.fullScreenHide();
                        }
                    });

                }
            });
        },
        passCfg: function () {
            var selections = $('#userTable').bootstrapTable('getSelections');
            if (selections.length == 0) {
                noty({
                    text: "请勾选需要操作的记录",
                    layout: "center",
                    type: "error",
                    timeout: 1000,
                    theme: 'bootstrapTheme'
                });
                return false;
            }
            if (selections.length > 1) {
                noty({
                    text: "只能勾选一条需要操作的记录",
                    layout: "center",
                    type: "error",
                    timeout: 1000,
                    theme: 'bootstrapTheme'
                });
                return false;
            }
            BootstrapDialog.confirm({
                title: "用户密码重置",
                draggable: true,
                btnOKLabel: '是',
                btnCancelLabel: '否',
                message: '确定要重置用户【' + selections[0].CN_NAME + '[' + selections[0].LOGIN_NAME + ']】登录密码吗?',
                callback: function (result) {
                    if (result) {
                        $.ajax({
                            url: basePath + 'loginUser/reSetUserPwd.do',
                            type: 'POST',
                            data: {userId: selections[0].USER_ID},
                            async: true,
                            dataType: 'json',
                            beforeSend: function () {
                                MaskLoading.fullScreenShow("正在提交,请稍后...");
                            },
                            success: function (data) {
                                if (data.success) {
                                    noty({
                                        text: "用户密码重置成功,密码有效期为3天",
                                        layout: "center",
                                        type: "success",
                                        timeout: 1000,
                                        theme: 'bootstrapTheme'
                                    });
                                    MaskLoading.fullScreenHide();
                                    $.userInfoOper.refreshData();
                                } else {
                                    noty({
                                        text: data.message.errorMessage,
                                        layout: "center",
                                        type: "error",
                                        timeout: 1000,
                                        theme: 'bootstrapTheme'
                                    });
                                    MaskLoading.fullScreenHide();
                                }
                            },
                            error: function (data) {
                                noty({
                                    text: "服务器异常",
                                    layout: "center",
                                    type: "error",
                                    timeout: 1000,
                                    theme: 'bootstrapTheme'
                                });
                            },
                            complete: function () {
                                MaskLoading.fullScreenHide();
                            }
                        });
                    }
                }
            });
        },
        refreshData: function () {
            $('#userTable').bootstrapTable('refresh');
            $('#userTable').bootstrapTable('resetView');
        }
    };
    $.userSelect = {
        stateSelect: function (data) {
            $('#state-form').select2({
                placeholder: '请选择状态',
                width: "100%",
                data: $.userInfoMgr.state,
                minimumResultsForSearch: -1,
                multiple: false
            });
            console.log(JSON.stringify(data));
            if (data) {
                $("#state-form").val(data[0].id).trigger("change");
            }
        },

        developmentSelect: function (data) {
            $('#development-form').select2({
                placeholder: '请选择部门',
                width: "100%",
                data: data,
                minimumResultsForSearch: -1,
                multiple: false,
                ajax: {
                    url: basePath + "organization/getOrganizationByType.do?type=1",  // 异步请求地址
                    dataType: "json", // 数据类型
                    type: "GET",
                    processResults: function (data) {
                        let dataOrder = $.map(data, function (obj) {
                            obj.id = obj.organizationId;
                            obj.text = obj.name;
                            return obj;
                        });
                        return {
                            results: dataOrder
                        };
                    }
                }
            });
            if (data) {

                $("#development-form").val(data[0].id).trigger("change");
            }

        },
        roleSelect: function (data) {
            $('#role-form').select2({
                placeholder: '请选择角色',
                width: "100%",
                data: data,
                minimumResultsForSearch: -1,
                multiple: false,
                ajax: {
                    url: basePath + "roleInfo/getRoleByRoleId.do",  // 异步请求地址
                    dataType: "json", // 数据类型
                    type: "GET",
                    processResults: function (data) {
                        let dataOrder = $.map(data, function (obj) {
                            obj.id = obj.roleId;
                            obj.text = obj.name;
                            return obj;
                        });
                        return {
                            results: dataOrder
                        };
                    }
                }
            });
            if (data) {

                $("#role-form").val(data[0].id).trigger("change");

            }

        }
    };
    $(function () {
        $.userInfoMgr.initButton();
        $.initTree.initTreePanel();
        $.initTree.treeResize();
    })
})(jQuery);
